package cn.edu.zafu.bigdata.zqt.studentsystem.utils;

import cn.edu.zafu.bigdata.zqt.studentsystem.cli.StudentManagerSystem;
import cn.edu.zafu.bigdata.zqt.studentsystem.constant.FileConst;
import cn.hutool.json.JSONUtil;

import java.io.FileOutputStream;
import java.nio.charset.StandardCharsets;

/**
 * 文件工具类
 *
 * @author zqt
 */
public class FileUtils {

    /**
     * 保存数据到文件
     */
    public static void updateData() {
        String jsonStr = JSONUtil.toJsonStr(StudentManagerSystem.studentList);
        try (FileOutputStream fileOutputStream = new FileOutputStream(FileConst.FILE_PATH)) {
            fileOutputStream.write(jsonStr.getBytes(StandardCharsets.UTF_8));
        } catch (Exception e) {
            System.err.println(e.getMessage());
        }
    }
}
